import matplotlib.pyplot as plt
import numpy as np

# 原始数据
labels      = ['5', '10', '15', '20']
acc_values  = [98.71, 99.38, 99.01, 98.59]

# 均匀放置柱子：0,1,2,3
x_pos = np.arange(len(labels))          
width = 0.55                            # 保持窄一些

fig, ax = plt.subplots(figsize=(4, 4))    # 适中画布宽度

colors = ['#a0bfd5', '#7da8c7', '#6990ab', '#627584']
bars = ax.bar(x_pos, acc_values, width=0.55,
              color=colors,
              )

# 轴标签与标题
ax.set_title('Accuracy vs Expert Count', fontsize=16, fontweight='bold')
ax.set_xlabel('Number of Experts', fontsize=14)
ax.set_ylabel('Accuracy (%)', fontsize=14)

# X 轴刻度：位置用 x_pos，显示文本用 labels
ax.set_xticks(x_pos)
ax.set_xticklabels(labels, fontsize=12)

# Y 轴范围与刻度
ax.set_ylim(98, 99.5)
ax.set_yticks(np.arange(98, 99.6, 0.3))
ax.yaxis.set_major_formatter('{:.1f}'.format)
ax.tick_params(axis='y', labelsize=13) 

# 在柱子上方标注准确率
for bar in bars:
    h = bar.get_height()
    ax.text(bar.get_x() + bar.get_width()/2,
            h + 0.02,
            f'{h:.2f}%', ha='center', va='bottom', fontsize=12)

# 调整上下边距，压缩上下空间
plt.subplots_adjust(top=0.85, bottom=0.15)

plt.tight_layout()
plt.savefig('ccfa.png')
